import Vue from 'vue'
import none from '@/assets/common/bigUserHeader.png'

Vue.directive('lazy', {
  inserted(el, binding) {
    const observer = new IntersectionObserver(([{ isIntersecting }]) => {
      if (isIntersecting) {
        el.addEventListener('error', () => {
          el.src = none
        })
        el.src = binding.value
        observer.unobserve(el)
      }
    }, { threshold: 0 })
    observer.observe(el)
  }
})
